package rjeutsky.ui;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import rjeutsky.models.Publication;

public class PublicationSetSelectorRequest extends ConsoleRequest<Set<Long>> {
	
	private List<Publication> options;
	
	public List<Publication> getOptions() {
		return options;
	}

	public void setOptions(List<Publication> options) {
		this.options = options;
	}

	@Override
	protected void queryConsole() {
		value = new HashSet<Long>();
		IntegerConsoleRequest request = new IntegerConsoleRequest();
		int index = -1;
		request.setRequestText("enter variant number");
		while (index != 0) {
			index = -1;
			while (!(index >= 0 && index <= options.size())) {
				request.Run();
				index = request.getValue();
			}
			
			if (index != 0) {
				value.add(options.get(index-1).getId());
			}
		}
	}
	
	@Override
	protected void showRequest() {
		super.showRequest();
		System.out.println("0 - finish selections");
		int i = 0;
		for (Publication option : options) {
			System.out.println(String.format("%1$d - %2$s", ++i, option.toString()));
		}
	}
}
